package com.ys.controller.web.business;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bo.vo.W;
import com.ys.entity.business.TpQuestion;
import com.ys.service.sys.CommonApiService;
import com.ys.util.DateUtil;
import com.ys.util.shiro.ShiroUtils;

@Controller
@RequestMapping("/web/business/tpQuestion")
public class WebTpQuestionController {
	
	private static Long MENU_ID = 16L;
	
	@Autowired
	private CommonApiService<TpQuestion> commonService;
	
	/*
	 * 新增
	 */
	@GetMapping("/toAdd")
	public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response){

		TpQuestion entity = new TpQuestion();
		
		String yyMMdd = DateUtil.getYYYY_MM_DD(new Date()).replace("-", "").substring(2);
		
		Integer numToday = 3;
		String codeLast = "000" + (numToday + 1);
		
		entity.setCode("WTDJ-" + yyMMdd + "-" + codeLast);
		entity.setUserName(ShiroUtils.getUserName());
		entity.setVGsJc(ShiroUtils.getCidName());
		entity.setCidName(ShiroUtils.getCid());
		entity.setDeptName(ShiroUtils.getOrgName());
		entity.setvGsJcsj(ShiroUtils.getCidName());
		entity.setvGsBmsj(ShiroUtils.getCid());
		entity.setNamesj(ShiroUtils.getUserName());
		entity.setDeptsj(ShiroUtils.getOrgName());
		entity.setCreateUserId(ShiroUtils.getUserId());
		entity.setNameyyr(ShiroUtils.getUserName());
		entity.setCreateCodeCompany(ShiroUtils.getCid());
		entity.setCodesj(ShiroUtils.getUserId());
		entity.setDeptyyr(ShiroUtils.getOrgName());

		try {
			return commonService.toAdd(model, entity, MENU_ID, null, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
	
	/*
	 * 新增
	 */
	@GetMapping("/toEdit")
	public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id){

		try {
			return commonService.toEdit(model, id, new TpQuestion(), MENU_ID, null, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
}